<?php
namespace Admin\Controller;

use think\Controller;

class BaseController extends Controller
{
	public function _initialize()
	{
		$admin_id = session('admin_id');
		$admin_username = session('admin_username');
		if(!isset($admin_id) || !isset($admin_username)){
			$this->redirect('public/login');
		}
	}
	/**
     * 图片上传方法
     * @return array|bool
     */
	public function upload(){
		if(empty($_FILES)){
			$this->error("请选择上传文件！");
		}else{
            $upload = new \Think\Upload();// 实例化上传类
            $upload->maxSize   = 3145728 ;// 设置附件上传大小
            $upload->exts      = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
            $upload->rootPath  = './Uploads/'; // 设置附件上传根目录
            $upload->savePath  = ''; // 设置附件上传（子）目录
            // 上传文件
            $info   =   $upload->upload();
            if(!$info) {// 上传错误提示错误信息
            	$this->error($upload->getError());
            }else{// 上传成功 获取上传文件信息
            	return $info;
            }
        }
    }
}